package database.service;

import database.DAO.RelationDAO;

import java.util.List;

public class RelationService {
    private RelationDAO relationDAO=new RelationDAO();

    //注意不要把?写在''里面
    public List<Object[]> queryFriendListByUserName(String userName){
        return relationDAO.queryArrayList(
                "SELECT user_name,user_status FROM user_login_status " +
                        "WHERE user_id IN( " +
                        "SELECT friend_id FROM relation " +
                        "WHERE  user_name=? AND friend_name!='' " +
                        "UNION ALL " +
                        "SELECT user_id FROM relation " +
                        "WHERE friend_name=? AND user_name!='')",
                userName,userName
        );
    }
    public List<Object> queryGroupNumbersListByUserName(String groupName){
        return relationDAO.queryColumnList(
                "SELECT user_name FROM relation WHERE group_name=?",
                groupName
        );
    }

    public List<Object> queryIdsByGroupName(String groupName){
        return  relationDAO.queryColumnList(
                "select user_id from relation where group_name=?",groupName
        );
    }
}
